<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>路由管理</title>
</head>
<body>
    <div id="app">
        <div class="header">
            <h3>头部</h3>
        </div>
        <div class="left">
            <p>
                <ul>
                    <li><a href="#/foo">Go Foo</a></li>
                    <li><a href="#/bar">Go Bar</a></li>
                    <!-- 使用 router-link 组件来导航. -->
                    <!-- 通过传入 `to` 属性指定链接. -->
                    <!-- <router-link> 默认会被渲染成一个 `<a>` 标签 -->
                    <li><router-link to="/foo">Go to Foo</router-link></li>
                    <li><router-link to="/bar">Go to Bar</router-link></li>
                </ul>
            </p>
        </div>
        <div class="main">
        <!-- 路由出口 -->
        <!-- 路由匹配到的组件将渲染在这里 -->
        <router-view></router-view>
        </div>
    </div>
    <script src="./node_modules/vue/dist/vue.js"></script>
    <script src="./node_modules/vue-router/dist/vue-router.js"></script>
    <script>
        //1.定义路由组件
        const Foo={
            template:"<div> 我是foo组件 </div>"
        }
        const Bar={
            template:"<div> 我是bar组件 </div>"
        }
        //2.定义路由，并将组件注册到路由当中
        const router = new VueRouter({
            //!!!注意是routes，不是routers
            routes:[
                {path:"/foo",component:Foo},
                {path:"/bar",component:Bar}
            ]
        })
        new Vue({
            el:"#app",
            //3.将路由注册到Vue实例当中去
            router:router
        })
    </script>
</body>
</html>